package tests.db;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
import java.util.ArrayList;

import struct.*;
import db.DBManager;

/**
 * Tests Interest(tables include: fInterest, aInterest, dInterest) and
 *  History (tables include: fHistory, aHistory, dHistory) related methods.
 * @author Gabrielle DuBois
 */
public class DBManagerTest03 {
    private DBManager dbm;

    @BeforeClass
    public static void setUpAll() throws Exception{
        //add things to the database

    }


   @Before
    public void setUp() throws Exception{
        //todo before each @Test
        dbm = new DBManager();
    }

   @After
    public void tearDown() throws Exception {
        //todo after each @Test
        dbm.close();
    }

   @AfterClass
    public static void tearDownAll() throws Exception{
        //delete things that were added to the database!
        System.out.println("DBManagerTest.java: Cleaning up after all tests...");
        
        System.out.println("DBManagerTest.java: Done.");
    }

   @Test
    public void testgetInterestsAdult() throws Exception{
       String first = "Joe";
       String last = "Barnier";
       String dob = "12/31/1985";
       String classification = "adults";

       System.out.println(dbm.getIndividual(first, last, dob).getAttributes()[8]);

       String[] joeKey = {first, last, dob};
       ArrayList<Interest> i = dbm.getInterests(classification, joeKey);
       Object[] temp;

       if (i.size()>0){

           System.out.println("Minitry Interest of: "+first+" "+last+" "+dob);
           for(int m=0;m<i.size();m++){
               temp = i.get(m).getAttributes();
               for(int n=0;n<temp.length;n++){
                    System.out.print("'"+temp[n]+"' ");
               }
               System.out.println("");
           }
           System.out.println("");
       }
    }//testgetInterestsAdult()

   @Test
    public void testgetHistoriesAdult() throws Exception{
       String first = "Joe";
       String last = "Barnier";
       String dob = "12/31/1985";
       String classification = "adults";

       String[] joeKey = {first, last, dob};
       ArrayList<History> h = dbm.getHistories(classification, joeKey);
       Object[] temp;

       if(h.size()>0){
           System.out.println("Ministry History of: "+first+" "+last+" "+dob);
           for(int m=0;m<h.size();m++){
               temp = h.get(m).getAttributes();
               for(int n=0;n<temp.length;n++){
                    System.out.print("'"+temp[n]+"' ");
               }
               System.out.println("");
           }
           System.out.println("");
       }
    }//testgetHistoriesAdult()

   @Test
    public void testgetInterestsDependent() throws Exception{
       String first = "Maggie";
       String last = "Otto";
       String dob = "02/29/2020";
       String classification = "dependents";

       String[] key = {first, last, dob};
       ArrayList<Interest> i = dbm.getInterests(classification, key);
       Object[] temp;

       if (i.size()>0){

           System.out.println("Minitry Interest of: "+first+" "+last+" "+dob);
           for(int m=0;m<i.size();m++){
               temp = i.get(m).getAttributes();
               for(int n=0;n<temp.length;n++){
                    System.out.print("'"+temp[n]+"' ");
               }
               System.out.println("");
           }
           System.out.println("");
       }
    }//testgetInterestsDependent()

   @Test
    public void testgetHistoriesDependent() throws Exception{
       String first = "Maggie";
       String last = "Otto";
       String dob = "02/29/2020";
       String classification = "dependents";

       String[] key = {first, last, dob};
       ArrayList<History> h = dbm.getHistories(classification, key);
       Object[] temp;

       if(h.size()>0){
           System.out.println("Ministry History of: "+first+" "+last+" "+dob);
           for(int m=0;m<h.size();m++){
               temp = h.get(m).getAttributes();
               for(int n=0;n<temp.length;n++){
                    System.out.print("'"+temp[n]+"' ");
               }
               System.out.println("");
           }
           System.out.println("");
       }
    }//testgetHistoriesDependent()

   @Test
    public void testgetInterestsFamily() throws Exception{
       String name = "DuBois";
       String phone = "(920)555-5555";
       String classification = "families";

       String[] key = {name, phone};
       ArrayList<Interest> i = dbm.getInterests(classification, key);
       Object[] temp;

       if (i.size()>0){

           System.out.println("Minitry Interest of: "+name+" "+phone);
           for(int m=0;m<i.size();m++){
               temp = i.get(m).getAttributes();
               for(int n=0;n<temp.length;n++){
                    System.out.print("'"+temp[n]+"' ");
               }
               System.out.println("");
           }
           System.out.println("");
       }
    }//testgetInterestsFamily()

   @Test
    public void testgetHistoriesFamily() throws Exception{
       String name = "DuBois";
       String phone = "(920)555-5555";
       String classification = "families";

       String[] key = {name, phone};
       ArrayList<History> h = dbm.getHistories(classification, key);
       Object[] temp;

       if(h.size()>0){
           System.out.println("Ministry History of: "+name+" "+phone);
           for(int m=0;m<h.size();m++){
               temp = h.get(m).getAttributes();
               for(int n=0;n<temp.length;n++){
                    System.out.print("'"+temp[n]+"' ");
               }
               System.out.println("");
           }
           System.out.println("");
       }
    }//testgetHistoriesFamily()

}//DBManagerTest03